#include <linux/init.h>
#include <linux/module.h>
#include <linux/sched.h>
#include <linux/init_task.h>
#include <linux/kthread.h>

MODULE_LICENSE("GPL");

static char *prefix;
static int show_task(struct task_struct *);

static int module_task_threadfn(void *data __attribute__ ((unused))) {
	printk(KERN_ALERT "thread created. \n");
	
	return 0;
}

static int __init module_task_init(void) {
	struct task_struct *task;
	struct list_head *list;

	show_task(current);

	list_for_each(list, &init_task.children) {
		task = list_entry(list, struct task_struct, sibling);

		show_task(task);
	}

	printk(KERN_INFO "creating thread %smod...", prefix);
	kthread_run(module_task_threadfn, NULL, "%smod", prefix);

	return 0;
}

static int show_task(struct task_struct *task) {
	printk(KERN_ALERT "pid %d, name %s\n", task->pid, task->comm);

	return 0;
}

static void __exit module_task_exit(void) {
	printk(KERN_ALERT "module exited. \n");

	return;
}

module_param(prefix, charp, S_IRUGO);

module_init(module_task_init);
module_exit(module_task_exit);

